package edu.fsu.cs.SHPE;

import java.net.ConnectException;

import android.app.Activity;
import android.os.Bundle;
import android.text.util.Linkify;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class SpeakerActivity extends Activity {
	private static final String TAG = "edu.fsu.cs.SHPE.SpeakerActivity";
	
	
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.speaker);
		setTitle("Speaker Information");
		
		SpeakerContainer speakers = null;
		try {
			speakers = new SpeakerContainer(Conference.insertId(getString(R.string.getSpeaker), getIntent().getLongExtra("id", -1)));
		} catch (ConnectException e) {
			Toast.makeText(this, "Unable to Connect to Server", Toast.LENGTH_SHORT).show();
			e.printStackTrace();
		}
		
		if(speakers == null){
			Log.i(TAG, "Unable to get speaker");
			finish();
		}
		
		Speaker tmpSpeaker = speakers.get(0);
		
		TextView tmp;
		
		
		if(tmpSpeaker.getPhoto() != null){
			ImageView image = (ImageView)findViewById(R.id.imgPhoto);
			image.setImageDrawable(tmpSpeaker.getPhoto());
			image.setVisibility(View.VISIBLE);
		}
		
		if(tmpSpeaker.getFirstName() != null){
			tmp = (TextView)findViewById(R.id.txtName);
			tmp.setText(tmpSpeaker.getFirstName() + " " + tmpSpeaker.getLastName());
			tmp.setVisibility(TextView.VISIBLE);
		}
		
		
		if(tmpSpeaker.getOrganization() != null){
			tmp = (TextView)findViewById(R.id.txtOrganization);
			tmp.setText(tmpSpeaker.getOrganization());
		}
		
		if(tmpSpeaker.getTitle() != null){
			tmp = (TextView)findViewById(R.id.txtTitle);
			tmp.setText(tmpSpeaker.getTitle());
			tmp.setVisibility(TextView.VISIBLE);
		}
		
		if(tmpSpeaker.getBiography() != null){
			tmp = (TextView)findViewById(R.id.txtBio);
			tmp.setText(tmpSpeaker.getBiography());
		}
		
		
		if(tmpSpeaker.getEmail() != null){
			tmp = (TextView)findViewById(R.id.txtEmail);
			tmp.setText(tmpSpeaker.getEmail());
			Linkify.addLinks(tmp, Linkify.EMAIL_ADDRESSES);
		}
		
		if(tmpSpeaker.getWebsite() != null){
			tmp = (TextView)findViewById(R.id.txtWebsite);
			tmp.setText(tmpSpeaker.getWebsite());
			Linkify.addLinks(tmp, Linkify.WEB_URLS);
		}
		
		if(tmpSpeaker.getLinkedIn() != null){
			tmp = (TextView)findViewById(R.id.txtLinkedIn);
			tmp.setText(tmpSpeaker.getLinkedIn());
			Linkify.addLinks(tmp, Linkify.WEB_URLS);
			tmp.setVisibility(View.VISIBLE);
		}
		
		
		/*
		if(tmpSpeaker.getFacebook() != null){
			tmp = (TextView)findViewById(R.id.txtFacebook);
			tmp.setText(tmpSpeaker.getFacebook());
			//Linkify.addLinks(tmp, Linkify.WEB_URLS);
			tmp.setVisibility(View.VISIBLE);
		}
		*/
		
				
	}

}
